<template>
<!--   基地负责人审核而-->
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='search'>
        <a-row :gutter='24'>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='订单号'>
              <a-input placeholder='请输入订单号' v-model='queryParams.orderNo' allowClear></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="提交审核时间">
              <a-range-picker :style="{width: '100%'}" format="YYYY-MM-DD"
                              :placeholder="['开始时间', '结束时间']"
                              v-model="rangePikerDate2"
                              @change="onQueryDateChange2" />
            </a-form-item>
          </a-col>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='状态'>
              <a-select v-model='queryParams.state' placeholder='请选择状态'>
                <a-select-option v-for='(d,i) in stateList' :key='d.id' :value='d.id'>{{ d.value }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if='toggleSearchStatus'>
            <a-col :xl='6' :lg='7' :md='8' :sm='24'>
              <a-form-item label='客户'>
                <a-input placeholder='请输入客户名称' v-model='queryParams.user' allowClear></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl='6' :lg='7' :md='8' :sm='24'>
              <a-form-item label='业务员'>
                <a-input placeholder='请输入业务员' v-model='queryParams.businessPerson' allowClear></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl='6' :lg='7' :md='8' :sm='24'>
              <a-form-item label='出库时间'>
                <a-range-picker :style="{width: '100%'}" format='YYYY-MM-DD'
                                :placeholder="['开始时间', '结束时间']"
                                v-model='rangePikerDate'
                                @change='onQueryDateChange' />
              </a-form-item>
            </a-col>
            <a-col :xl='6' :lg='7' :md='8' :sm='24'>
              <a-form-item label='来源'>
                <!--              （-1待出库，0已出库，1删除，2撤销）-->
                <!--              <a-input placeholder='请选择状态' v-model='queryParam.state'></a-input>-->
                <a-select v-model='queryParams.source' placeholder='请选择来源'>
                  <a-select-option v-for='(d,i) in sourceList' :key='d.id' :value='d.value'>{{ d.value }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='search' icon='search'>查询</a-button>
              <a-button type='primary' @click='resetSearch' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <a-button type='primary' icon='download' :loading="exportLoading"  @click="handleExportXlsList('出库单')">导出Excel</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
        <i class='anticon anticon-info-circle ant-alert-icon'></i> 已选择 <a
        style='font-weight: 600'>{{ selectedRowKeys.length }}</a>项
        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>
      </div>
      <a-table
        ref='table'
        size='middle'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='outOrderDataSource'
        :pagination='mainPagination'
        :loading='loading'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        @change='mainPaginationChange'
        :scroll='{ x: true }'>

        <template slot='htmlSlot' slot-scope='text'>
          <div v-html='text'></div>
        </template>
        <template slot='imgSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无图片</span>
          <img v-else :src='getImgView(text)' height='25px' alt=''
               style='max-width:80px;font-size: 12px;font-style: italic;' />
        </template>
        <template slot='fileSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无文件</span>
          <a-button
            v-else
            :ghost='true'
            type='primary'
            icon='download'
            size='small'
            @click='uploadFile(text)'>
            下载
          </a-button>
        </template>

        <span slot='action' slot-scope='text, record'>
            <a @click='editModalShow(record)' style='margin-right: 5px;'>详情</a>
          <a-divider v-if='record.state==0' type='vertical' />
           <a-button  v-has='"outOrder:jidiSure"'  v-if='record.state==3' style='display: inline-block' type='primary' :loading='sureOutLoading'
                     @click='editModalShow(record)'>基地负责人审核</a-button>
           <a-button v-has='"outOrder:jidiSureBack"'  v-if='record.state==1' style='display: inline-block' type='yellow' :loading='sureOutLoading'
                     @click='editModalShow(record)'>撤销审核</a-button>

          <a-button v-if='record.state==0' style='display: inline-block' type='primary'
                    @click='handleExportXlsOut(record)'>配/提货单</a-button>
         <a-button v-if='record.state==4' style='display: inline-block' type='primary'
                   @click='handleExportXlsAccont(record)'>结算单导出</a-button>

<!--         <a v-if='record.sealNo' @click='afterSaleModalShow(record)'
            style='margin-right: 5px;color:darkgreen !important;'>售后单</a>
          <a-divider v-if='record.sealNo' type='vertical' />-->
          <a-button v-if='record.sealNo' style='display: inline-block;color:darkgreen !important;' type='yellow' :loading='sureOutLoading'
                    @click='afterSaleModalShow(record)'>售后单</a-button>

        </span>

      </a-table>
    </div>

    <!--    <flowerOutorder-modal ref='modalForm' @ok='modalFormOk'></flowerOutorder-modal>-->
    <a-modal v-model:visible='addOrEditVisible' width='95%' :title='firstModalTitle' @ok='saveOutOrderAddOrEdit'
             :maskClosable='false'>
      <div>
        <a-row>
          <a-col :span='8'>
            <div style='display: inline-block;width: 100px;'>订单号：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='outOrder.orderNo' placeholder='自动生成' disabled />
            </div>
          </a-col>
          <a-col :span='8'>
            <div style='display: inline-block;color: red;'>*</div>
            <div style='display: inline-block;width: 100px;'>是否开票：</div>
            <div style='display: inline-block;width: 70%'>
              <a-radio-group v-model='outOrder.isinvoice' @change='isinvoiceChange' disabled='disabled'>
                <a-radio value='是' key='是'>是</a-radio>
                <a-radio value='否' key='否'>否</a-radio>
              </a-radio-group>
            </div>
          </a-col>
          <a-col :span='8'>
            <div style='display: inline-block;color: red;'>*</div>
            <div style='display: inline-block;width: 100px;'>账期：</div>
            <div style='display: inline-block;'>
              <a-radio-group v-model='outOrder.period' @change='periodChange' disabled>
                <a-radio v-for='(item,index) in periodList' :value='item'>{{ item }}</a-radio>
              </a-radio-group>
            </div>
          </a-col>
        </a-row>
        <a-row style='margin-top: 10px'>
          <a-col :span='8'>
            <div style='display: inline-block;color: red;'>*</div>
            <div style='display: inline-block;width: 80px;'>客户名称：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='outOrder.user' placeholder='请输入客户名称' :disabled='disabled.user' />
            </div>
          </a-col>
          <a-col :span='8'>
            <div style='display: inline-block;color: red;'>*</div>
            <div style='display: inline-block;width: 80px;'>客户电话：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='outOrder.phone' placeholder='请输入客户电话' :disabled='disabled.phone' />
            </div>
          </a-col>
          <a-col :span='8'>
            <div style='display: inline-block;color: red;'>*</div>
            <div style='display: inline-block;'>客户余额：</div>
            <div style='display: inline-block;'>
              <a-input v-model='outOrder.customMoney' disabled />
            </div>
          </a-col>

        </a-row>

        <a-row style="margin-top: 10px">
          <a-col :span='8'>
            <div style='display: inline-block;color: red;'>*</div>
            <div style='display: inline-block;width: 100px;'>收件人：</div>
            <div style='display: inline-block;'>
              <a-input v-model='outOrder.touser'  :disabled='disabled.businessPerson'/>
            </div>
          </a-col>
          <a-col :span='8'>
            <div style='display: inline-block;color: red;'>*</div>
            <div style='display: inline-block;width: 80px;'>收件电话：</div>
            <div style='display: inline-block;'>
              <a-input v-model='outOrder.tophone'  :disabled='disabled.businessPerson'/>
            </div>
          </a-col>
          <a-col :span='8'>
            <div style='display: inline-block;color: red;'>*</div>
            <div style='display: inline-block;width: 80px;'>地址：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='outOrder.address' :disabled='disabled.businessPerson'/>
            </div>
          </a-col>
        </a-row>
        <a-row style='margin-top: 10px'>
          <a-col :span='8'>
            <div style='display: inline-block;color: red;'>*</div>
            <div style='display: inline-block;width: 80px;'>出库人：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='outOrder.stockOutUser' placeholder='请输入出库人' :disabled='disabled.stockOutUser' />
            </div>
          </a-col>
          <a-col :span='8'>
            <div style='display: inline-block;color: red;'>*</div>
            <div style='display: inline-block;width: 100px;'>出库时间：</div>
            <div style='display: inline-block;width: 70%'>
              <a-date-picker v-model:value='outOrder.stockInTime' :valueFormat='dateFormat' placeholder='请选择出库时间'
                             :disabled='disabled.stockInTime' />
            </div>
          </a-col>
          <a-col :span='8'>
            <div style='display: inline-block;color: red;'>*</div>
            <div style='display: inline-block;width: 100px;'>业务员：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='outOrder.businessPerson' placeholder='请输入业务员' :disabled='disabled.businessPerson' />
            </div>
          </a-col>
        </a-row>
        <a-row style='margin-top: 10px'>
          <a-col :span='8'>
            <div style='display: inline-block;width: 100px;'>司机：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='outOrder.carDerver' placeholder='请输入司机' :disabled='disabled.carDerver' />
            </div>
          </a-col>
          <a-col :span='8'>
            <div style='display: inline-block;width: 100px;'>车牌：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='outOrder.carNo' placeholder='请输入车牌' :disabled='disabled.carNo' />
            </div>
          </a-col>
          <a-col :span='8'>
            <div style='display: inline-block;width: 100px;'>司机电话：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='outOrder.carPhone' placeholder='请输入司机电话' :disabled='disabled.carPhone' />
            </div>
          </a-col>
        </a-row>
        <a-row style='margin-top: 10px'>
          <a-col :span='8'>
            <div style='display: inline-block;width: 100px;'>总数量：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='outOrder.number' placeholder='自动生成'  disabled  />
            </div>
          </a-col>
          <a-col :span='8'>
            <div style='display: inline-block;width: 100px;'>总金额：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='outOrder.totalprice' placeholder='自动生成' disabled />
            </div>
          </a-col>
        </a-row>

        <a-row style='margin-top: 10px'>
          <a-col :span='24'>
            <div style='display: inline-block;width: 100px;'>备注：</div>
            <div style='display: inline-block;width: 85%'>
              <a-textarea v-model='outOrder.remarks' placeholder='请输入备注' :disabled='disabled.remarks' />
            </div>
          </a-col>
        </a-row>
        <a-row style='margin-top: 10px'>
          <a-col :span='24'>
            <div style='display: inline-block;width: 100px;'>物流信息：</div>
            <div style='display: inline-block;width: 85%'>
              <a-textarea v-model='outOrder.logistics' placeholder='请输入物流信息' :disabled='disabled.logistics' />
            </div>
          </a-col>
        </a-row>
      </div>
      <a-divider />
      <div style='margin-top: -20px'>

        <div>
          <a-row>
            <a-col  >

              <div style='display:inline-block;width: 100%'>
                <div style='font-size: 20px;color: #0742f3;margin-bottom: 3px'><span
                  style='margin-right: 20px;'>销售商品 </span>

                  <span style='font-size: 14px;color: black;'>总价合计：</span><span
                    style='color: red;margin-right: 20px'>{{ allTotalPrice }}</span>
                  <span style='font-size: 14px;color: black;'>数量合计：</span><span style='color: red'>{{ allTotalNum
                    }}</span>
                </div>

                <div style='margin-top: 7px'>
                  <a-table :columns='varietyColumns' :data-source='varietyDataSource'
                           bordered row-key='varietyCode'
                           :loading='varietyLoading'
                           :pagination='false'
                           :scroll='{ x: true, y: 300 }'
                  >

                  </a-table>
                </div>
              </div>
            </a-col>
            <a-col   v-if='outOrder.source!="手动出库"'>
              <div style='display: inline-block;width: 100%; '>
                <div style='font-size: 20px;color: #0742f3;margin-bottom: 3px'>
                  <span style='margin-right: 20px;'>拆分后详情</span>
                  <span style='font-size: 14px;color: black;'>总价合计：</span><span
                  style='color: red;margin-right: 20px'>{{ totalPrice2 }}</span>
                  <span style='font-size: 14px;color: black;'>数量合计：</span><span style='color: red'>{{ totalNum2
                  }}</span>
                </div>
                <a-table :columns='varietyColumnsDetail' :data-source='varietyDataSourceDetail'
                         bordered row-key='uuid'
                         :loading='varietyLoading'
                         :pagination='false'
                         :scroll='{ x: true, y: 300 }'
                ></a-table>
              </div>
            </a-col>
          </a-row>
        </div>
      </div>
      <template slot='footer'  style='margin-top: 5px;float: right'>
        <a-button @click='cancelOutOrderAddOrEdit()' :loading='sureOutLoading' >取消</a-button>
        <a-button v-has='"outOrder:jidiSure"' v-if='outOrder.state==3'  :loading='sureOutLoading'   type='primary' @click='finalSure()'>基地负责人审核</a-button>
        <a-button v-has='"outOrder:jidiSureBack"' type="danger" v-if='outOrder.state==1'  :loading='sureOutLoading'   @click='finalSureBack()'>撤销基地负责人审核</a-button>

      </template>
    </a-modal>


    <!--售后订单的弹窗-->
    <a-modal v-model:visible='afterSaleVisible' width='85%' title='售后单' @ok='suerAfterSale'>
      <div>
        <a-row>
          <a-col :span='12'>
            <div style='display: inline-block;width: 80px;'>销售单号：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='afterSale.orderNo' placeholder='无数据' disabled />
            </div>
          </a-col>
          <a-col :span='12'>
            <div style='display: inline-block;width: 80px;'>售后单号：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='afterSale.afOrderNo' placeholder='无数据' disabled />
            </div>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span='12'>
            <div style='display: inline-block;width: 80px;'>货损金额：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='afterSale.totalPrice' placeholder='无数据' disabled />
            </div>
          </a-col>
          <a-col :span='12'>
            <div style='display: inline-block;width: 80px;'>责任判定：</div>
            <div style='display: inline-block;width: 70%'>
              <a-input v-model='afterSale.responsibility' placeholder='无数据' disabled />
            </div>
          </a-col>
        </a-row>
        <a-row style='margin-top: 10px'>
          <a-col :span='24'>
            <div style='display: inline-block;width: 80px;'>售后理由：</div>
            <div style='display: inline-block;width: 85%'>
              <a-textarea v-model='afterSale.reason' placeholder='无数据' disabled />
            </div>
          </a-col>
        </a-row>
      </div>
      <a-divider />
      <div style='margin-top: -20px'>
        <div style='font-size: 20px;color: #0742f3;margin-bottom: 3px'>售后商品</div>
        <div style='margin-top: 7px'>
          <a-table :columns='afterSaleColumns' :data-source='afterSaleSource'
                   bordered row-key='id'
                   :loading='afterSaleLoading'>
          </a-table>
        </div>
      </div>
    </a-modal>
  </a-card>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import FlowerOutorderModal from './modules/FlowerOutorderModal'
import { downFile } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import { ifInteger, ifNumber } from '../../utils/ifNumber'
import { getUuid } from '../../utils/uuid'
import {ACCESS_TOKEN} from "@/store/mutation-types"
import {
  getFlowerVarietys, getFlowerOutorderinfo, flowerOutOrderAdd, flowerOutOrderEdit, getFlowerOutorder,
  flowerOutOrderDelete, flowerOutOrderDeleteBatch, flowerOutOrderSureOut, flowerOutOrderToWaitOut,
  flowerOutOrderDList, flowerOutOrderDAdd, flowerOutOrderDDelete, flowerAfSalesMain,
  queryFlowerOutOrderInfoListInfo, fiunalSure, fiunalSureBack, getCustomMoney, period,
} from '../../api/api'
import axios from 'axios'
import Vue from 'vue'

export default {
  name: 'FlowerOutorderList',
  mixins: [JeecgListMixin],
  components: {
    FlowerOutorderModal
  },
  data() {
    return {
      queryParams: {// 主页查询
        orderNo: '',//订单号
        state: '',//状态
        source: '',//来源（手动出库、销售系统）
        user: '',//客户
        sDate: '',//开始时间
        eDate: ''//结束时间
      },
      rangePikerDate: [],
      rangePikerDate2: [],
      // sourceBaseList: [],//基地列表
      // sourceGreenhouseList: [],//地块列表
      queryVarietyParams: {// 商品选择弹窗的查询
        variety: '',
        varietyCode: ''
      },
      sourceList: [{ id: '', value: '全部' }, { id: '1', value: '手动出库' }, { id: 2, value: '销售系统' }, { id: 3, value: '补货' }],
      stateList: [{ id: '', value: '全部' },{ id: '-1', value: '草稿' },{ id: '3', value: '待审核' },
        { id: 0, value: '库管确认出库' }, {id: 1,value: '基地负责人审核' },{id: 2,value: '运管备案' },
      ],
      periodList: [],//从后台取回的账期列表（上个账期，当前账期，下个账期）
      description: '出库单主表管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 50,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'state',
          customRender: function(text) {
            let stateString = ''
            switch (text) {
              case -1:
                stateString = '草稿'
                break
              case 3:
                stateString = '待审核'
                break
              case 0:
                stateString = '库管确认出库'
                break
              case 1:
                stateString = '基地负责人审核'
                break
              case 2:
                stateString = '运管备案'
                break
              default:
                stateString = ''
            }
            return stateString
          },
          width: 110
        },
        {
          title: '订单号',
          align: 'center',
          dataIndex: 'orderNo',
          width: 150
        },
        {
          title: '销售单号',
          align: 'center',
          dataIndex: 'sealNo',
          width: 150
        }, {
          title: '账期',
          align: 'center',
          width: 100,
          dataIndex: 'period'
        },
        {
          title: '来源',
          align: 'center',
          dataIndex: 'source',
          width: 80
        },
        {
          title: '出库数量',
          align: 'center',
          dataIndex: 'number',
          width: 100
        },

        {
          title: '客户',
          align: 'center',
          dataIndex: 'user',
          width: 100
        },
        {
          title: '联系电话',
          align: 'center',
          dataIndex: 'phone',
          width: 110
        },{
          title: '业务员',
          align: 'center',
          dataIndex: 'businessPerson',
          width: 70
        },{
          title: '是否开票',
          align: 'center',
          dataIndex: 'isinvoice',
          width: 50
        },{
          title: '提交审核时间',
          align: 'center',
          dataIndex: 'topresstime',
          width: 150
        }, {
          title: '基地负责人',
          align: 'center',
          dataIndex: 'finaSureUser',
          width: 90
        },{
          title: '基地负责人审核日期',
          align: 'center',
          dataIndex: 'finaSureTime',
          width: 90
        },{
          title: '运管备案',
          align: 'center',
          dataIndex: 'surepipeuser',
          width: 90
        },{
          title: '运管备案时间',
          align: 'center',
          dataIndex: 'surepipetime',
          width: 90
        },{
          title: '库管确认人',
          align: 'center',
          dataIndex: 'sureoutuser',
          width: 90
        },{
          title: '库管确认时间',
          align: 'center',
          dataIndex: 'sureouttime',
          width: 90
        },{
          title: '结算确认',
          align: 'center',
          dataIndex: 'accounter',
          width: 70
        },{
          title: '结算确认时间',
          align: 'center',
          dataIndex: 'accounttime',
          width: 90
        },
        {
          title: '创建日期',
          align: 'center',
          dataIndex: 'createTime',
          width: 140
        },

        {
          title: '创建人',
          align: 'center',
          dataIndex: 'createUser_dictText',
          width: 140
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
          fixed: 'right',
          width: 310
        }
      ],
      url: {
        list: '/flower/flowerOutorder/list',
        delete: '/flower/flowerOutorder/delete',
        deleteBatch: '/flower/flowerOutorder/deleteBatch',
        // exportXlsUrl: '/flower/flowerOutorder/exportXls',
        exportXlsUrl: '/flower/flowerOutorder/exportXlsAll',
        importExcelUrl: 'flower/flowerOutorder/importExcel'
      },
      dictOptions: {},
      outOrderDataSource: [],
      firstModalTitle: '',
      addOrEditFlag: 'add',//打开的弹窗是新增还是编辑的标识
      varietyLoading: false,//是否显示第一个弹窗中表格的加载状态
      selectVarietyLoading: true,//是否显示第二个弹窗中表格的加载状态
      addOrEditVisible: false,//是否打开新增或编辑的弹窗
      varietyVisible: false,//是否打开商品选择的弹窗
      outOrder: {
        user: '',
        phone: '',
        customMoney:'',//客户余额
        address: '',
        logistics: '',
        storehouse: '',
        carDerver: '',
        source: '',
        carNo: '',
        businessPerson: '',
        stockOutUser: '',
        carPhone: '',
        stockInTime: '',
        remarks: ''
      },
      dateFormat: 'YYYY-MM-DD',
      varietyColumns: [// 第一个弹窗拆分前表格的表头
        {
          title:'基地',
          align:"center",
          dataIndex: 'sourceBase_dictText',
          width: 120,
        },{
          title:'大棚',
          align:"center",
          dataIndex: 'sourceGreenhouse_dictText',
          width: 100,
        },{
          title: '冷库',
          dataIndex: 'storehouse_dictText',
          width: 100
        }, {
          title: '成本中心',
          dataIndex: 'cost_dictText',
          width: 120
        }, {
          title: '产品',
          dataIndex: 'variety',
          width: 100
        }, {
          title: '商品编码',
          dataIndex: 'varietyCode',
          width: 120
        }, {
          title: '规格',
          dataIndex: 'packingSpecifications',
          width: 90
        }, {
          title: '单位',
          dataIndex: 'flowerPoleLength',
          width: 110
        },
        /*{
          title: '等级',
          dataIndex: 'classes'
        },*/
        {
          title: '数量',
          dataIndex: 'number',
          scopedSlots: { customRender: 'number' },
          width: 100
        }, {
          title: '单价',
          dataIndex: 'price',
          width: 85
          // scopedSlots: { customRender: 'price' }
        }, {
          title: '总价',
          dataIndex: 'totalprice',
          scopedSlots: { customRender: 'totalprice' },
          width: 85
        }
        /*{
          title: '操作',
          dataIndex: 'operation',
          width: 130,
          align: 'center',
          scopedSlots: { customRender: 'operation' },
          fixed: 'right'
        }*/
      ],
      varietyColumnsDetail: [// 第一个弹窗拆分后表格的表头
        {
          title:'基地',
          align:"center",
          dataIndex: 'sourceBase_dictText',
          width: 120,
        },{
          title:'大棚',
          align:"center",
          dataIndex: 'sourceGreenhouse_dictText',
          width: 100,
        },
        {
          title: '冷库',
          dataIndex: 'storehouse_dictText',
          width: 100
        }, {
          title: '产品',
          dataIndex: 'variety',
          width: 100
        }, {
          title: '商品编码',
          dataIndex: 'varietyCode',
          width: 130
        }, {
          title: '规格',
          dataIndex: 'packingSpecifications',
          width: 85
        }, {
          title: '单位',
          dataIndex: 'flowerPoleLength',
          width: 100
        },
        {
          title: '数量',
          dataIndex: 'number',
          scopedSlots: { customRender: 'number' },
          width: 85
        }, {
          title: '单价',
          dataIndex: 'price',
          width: 70
          // scopedSlots: { customRender: 'price' }
        }, {
          title: '总价',
          dataIndex: 'totalprice',
          scopedSlots: { customRender: 'totalprice' },
          width: 70
        }
      ],
      selectVarietyColumns: [// 第二个弹窗的表头
        {
          title: '冷库',
          dataIndex: 'storehouse_dictText'
        }, {
          title: '产品',
          dataIndex: 'variety'
        }, {
          title: '商品编码',
          dataIndex: 'varietyCode'
        }, {
          title: '规格',
          dataIndex: 'packingSpecifications'
        }, {
          title: '单位',
          dataIndex: 'flowerPoleLength'
        }, {
          title: '库存',
          dataIndex: 'tagNum'
        }
      ],
      varietyDataSource: [],// 第一个弹窗中拆分前的商品列表
      varietyDataSourceDetail: [],// 第一个弹窗中拆分后的商品列表
      selectVarietyDataSource: [],// 第二个弹窗中可选择的商品列表
      selectVariety: {},// 第二个弹窗中已选择的商品
      mainPagination: {// 主页表格的分页
        total: 0,
        current: 1,
        pageSize: 10,//每页中显示10条数据
        showSizeChanger: true,
        pageSizeOptions: ['10', '20', '50', '100'],//每页中显示的数据
        showTotal: total => `共有 ${total} 条数据`  //分页中显示总的数据
      },
      varietyPagination: {// 商品选择弹窗中表格的分页
        total: 0,
        current: 1,
        pageSize: 5,//每页中显示5条数据
        showSizeChanger: true,
        pageSizeOptions: ['5', '10', '15', '20'],//每页中显示的数据
        showTotal: total => `共有 ${total} 条数据`  //分页中显示总的数据
      },
      disabled: {// 第一个弹窗中各控件是否禁用
        user: true,
        phone: true,
        address: true,
        logistics: true,
        carDerver: true,
        carNo: true,
        businessPerson: true,
        stockOutUser: true,
        carPhone: true,
        stockInTime: true,
        remarks: true,
        addButton: true,// 第一个弹窗中的新增商品的按钮是否显示
        number: true,// 第一个弹窗中的数量框输入是否禁用
        price: true,// 第一个弹窗中的单价框输入是否禁用
        totalprice: true,// 第一个弹窗中的总价框输入是否禁用

        isToMui: true,
        isDelete: true
      },
      outOrderRecord: {},// 选中编辑的出库单
      outorderInfoFlag: true,//选中编辑的出库单是否已经有商品，true为是，false为否
      mainLoading: false,
      allTotalPrice: 0,//编辑弹窗中所有商品的总价
      allTotalNum: 0,//编辑弹窗中所有商品的总数量
      toMuiDialogVisible: false,//拆分分订单的弹窗显示
      hoseLoading: false,//是否显示拆分弹窗中表格的加载状态
      hoseColumns: [{
        title: '冷库',
        dataIndex: 'storehouse',
        width: '40%',
        scopedSlots: { customRender: 'storehouse' }
      }, {
        title: '数量',
        dataIndex: 'number',
        width: '40%',
        scopedSlots: { customRender: 'number' }
      }, {
        title: '操作',
        dataIndex: 'operation',
        align: 'center',
        width: 60,
        scopedSlots: { customRender: 'operation' }
      }],//
      orderDetailID: '',//出库单子表的id，用于拆分订单时做主表id
      orderDetailTotalNumber: 0,//出库单子表的出库数量
      selectedHoseDataSource: [],//拆分d的数据
      afterSaleVisible: false,
      afterSale: {
        orderNo: '',//销售单号
        afOrderNo: '',//售后单号
        totalPrice: '',//货损金额
        responsibility: '',//责任判定
        reason: ''//售后理由
      },
      afterSaleColumns: [// 售后单弹窗中表格的表头
        {
          title: '产品',
          dataIndex: 'variety',
          width: 100
        }, {
          title: '商品编码',
          dataIndex: 'varietyCode',
          width: 100
        }, {
          title: '规格',
          dataIndex: 'packingSpecifications'
        }, {
          title: '单位',
          dataIndex: 'flowerPoleLength'
        }, {
          title: '销售价格',
          dataIndex: 'sealPrice'
        }, {
          title: '货损价格',
          dataIndex: 'afSealPrice'
        },
        {
          title: '货损数量',
          dataIndex: 'number'
        }
      ],
      afterSaleSource: [],
      afterSaleLoading: false,
      totalPrice2: 0,
      totalNum2: 0,
      exportLoading:false,
      sureOutLoading:false,
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  mounted() {
    this.queryFlowerOutorder()
  },
  created() {
    this.queryParams.state = '3'
    this.hoseList = JSON.parse(localStorage.getItem('ch_storehouse') ? localStorage.getItem('ch_storehouse') : '')
    this.getPeriod()
  },
  methods: {
    search() {// 主页中根据条件查询
      if (this.queryParams.source === '全部') {
        this.queryParams.source = ''
      }
      this.queryFlowerOutorder()
    },
    onQueryDateChange(date, dateString) {// 日期段选择改变时的回调
      this.queryParams.sDate = dateString[0]
      this.queryParams.eDate = dateString[1]
    },
    onQueryDateChange2(date, dateString) {// 日期段选择改变时的回调
      this.queryParams.topresDate = dateString[0]
      this.queryParams.topreeDate = dateString[1]
    },
    resetSearch() {// 重置查询
      this.queryParams = {// 主页查询
        orderNo: '',//订单号
        state: '',//状态
        source: '',//来源（手动出库、销售系统）
        user: '',//客户
        sDate: '',//开始时间
        eDate: ''//结束时间
      }
      this.rangePikerDate = []
      this.search()
    },
    searchFlowerVarietys() {//根据条件查询商品选择弹窗中的品商品列表
      let params = {
        pageNo: this.varietyPagination.current,
        pageSize: this.varietyPagination.pageSize,
        variety: this.queryVarietyParams.variety,
        varietyCode: this.queryVarietyParams.varietyCode
      }
      getFlowerVarietys(params).then(res => {
        if (res.success) {
          this.varietyPagination.total = res.result.total
          this.selectVarietyDataSource = res.result.records

          this.selectVarietyLoading = false
        } else {
          this.selectVarietyLoading = false
          this.$message.error(res.message)
        }
      })
    },
    mainPaginationChange(pagination) {
      this.mainPagination.current = pagination.current
      this.mainPagination.pageSize = pagination.pageSize
      this.queryFlowerOutorder()
    },
    varietyPaginationChange(pagination) {
      this.varietyPagination.current = pagination.current
      this.varietyPagination.pageSize = pagination.pageSize
      this.queryFlowerVarietys()
    },
    queryFlowerOutorder() {// 获取出库单
      this.loading = true
      this.outOrderDataSource.length = 0
      let params = {
        pageNo: this.mainPagination.current,
        pageSize: this.mainPagination.pageSize
      }
      params = { ...this.queryParams, ...params }
      getFlowerOutorder(params).then(res => {
        if (res.success) {
          this.mainPagination.total = res.result.total
          this.outOrderDataSource = res.result.records
          /*for(let item of this.outOrderDataSource){//查询客户的实时余额
            getCustomMoney({'userId':item.userid}).then(res=>{
              if (res.success){
                item.customMoney=res.result
              }
            })
          }*/
        } else {
          this.$message.error(res.message)
        }
        this.loading = false
      })
    },
    addModalShow() {//打开第一个弹窗(新增)
      this.addOrEditFlag = 'add'
      this.firstModalTitle = '新增'

      this.outOrder = {
        carDerver: '',
        carNo: '',
        stockOutUser: '',
        stockInTime: '',
        remarks: ''
      }
      this.varietyDataSource = []
      this.allTotalPrice = 0
      this.allTotalNum = 0
      this.addOrEditVisible = !this.addOrEditVisible
    },
    editModalShow(record) {//打开第一个弹窗(编辑)
      this.outOrderRecord = record
      this.addOrEditFlag = 'edit'
      this.firstModalTitle = '编辑'
      this.outOrder = record
      this.queryCustomMoney(record.userid)
      this.varietyDataSource.length = 0
      this.allTotalPrice = 0
      this.allTotalNum = 0
      this.queryFlowerOutorderinfo(record.id)
      this.queryFlowerOutorderinfoListInfo(record.id)

      this.disabled = {
        user: true,
        phone: true,
        address: true,
        logistics: true,
        carDerver: true,
        businessPerson: true,
        carNo: true,
        stockOutUser: true,
        carPhone: true,
        stockInTime: true,
        remarks: true,
        addButton: false,
        number: true,
        price: true,
        totalprice: true,
        isToMui: true,
        isDelete: true
      }

      this.addOrEditVisible = !this.addOrEditVisible
    },
    varietyModalShow() {//打开第二个弹窗
      /*设置下面这两行是为了处理再次打开商品选择弹窗时，
      还会在界面上保留上次选择商品而实际上没有选择任何商品的问题*/
      this.selectedRowKeys.length = 0
      this.selectionRows.length = 0

      this.selectVariety = {}
      this.varietyPagination = {// 商品选择弹窗中表格的分页
        total: 0,
        current: 1,
        pageSize: 5,//每页中显示5条数据
        showSizeChanger: true,
        pageSizeOptions: ['5', '10', '15', '20'],//每页中显示的数据
        showTotal: total => `共有 ${total} 条数据`  //分页中显示总的数据
      }
      this.queryFlowerVarietys()
      this.varietyVisible = !this.varietyVisible

    },
    queryFlowerOutorderinfo(orderId) {//获取第一个弹窗的拆分前商品数据
      this.varietyLoading = true
      let params = {
        orderId: orderId,
        pageNo: 1,
        pageSize: 10000
      }
      getFlowerOutorderinfo(params).then(res => {
        if (res.success) {
          let records = res.result.records
          if (records.length > 0) {
            this.outorderInfoFlag = true
          } else {
            this.outorderInfoFlag = false
          }

          for (let item of records) {
            this.allTotalPrice += item.totalprice * 10 / 10// 计算总价合计
            this.allTotalNum += item.number * 10 / 10// 计算总价合计
          }
          // 保留两位小数
          this.allTotalPrice = (this.allTotalPrice * 10 / 10).toFixed(2)

          this.varietyDataSource = records
        } else {
          this.$message.error(res.message)
        }
        this.varietyLoading = false
      })
    },
    queryFlowerOutorderinfoListInfo(orderId) {//获取第一个弹窗的拆分后商品数据
      this.varietyLoading = true
      let that = this
      let params = {
        mainid: orderId
      }
      queryFlowerOutOrderInfoListInfo(params).then(res => {
        if (res.success) {
          that.totalPrice2 = 0
          that.totalNum2 = 0
          this.varietyDataSourceDetail = res.result.records
          // 将uuid封装进varietyDataSourceDetail中的各用户对象中,为table中的key使用
          this.varietyDataSourceDetail.map(item => {
            item.uuid = getUuid()
            that.totalNum2 += item.number * 10 / 10
            that.totalPrice2 += item.totalprice * 10 / 10
          })
        } else {
          this.$message.error(res.message)
        }
        this.varietyLoading = false
      })
    },

    queryFlowerVarietys() {// 获取第二个弹窗中的商品列表
      this.selectVarietyLoading = true
      let params = {
        pageNo: this.varietyPagination.current,
        pageSize: this.varietyPagination.pageSize
      }
      getFlowerVarietys(params).then(res => {
        if (res.success) {
          this.varietyPagination.total = res.result.total
          this.selectVarietyDataSource = res.result.records

          // 将uuid封装进selectVarietyDataSource中的各用户对象中,为table中的key使用
          this.selectVarietyDataSource.map(item => {
            item.uuid = getUuid()
          })
        } else {
          this.$message.error(res.message)
        }
        this.selectVarietyLoading = false
      })
    },
    onVarietySelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys// 如果不加这两行的话无法单选
      this.selectionRows = selectionRows

      this.selectVariety = selectionRows[0]
    },
    varietyAdd() {// 第二个弹窗中的新增商品
    /*  if (JSON.stringify(this.selectVariety) !== '{}') {//判断this.selectVariety是否为空
        this.selectVariety.number = ''// 为selectVariety对象中添加number元素

        let varietyCodeFlag = false//第一个弹窗表格中的商品是否包含新添加的商品
        for (let item of this.varietyDataSource) {
          if (item.varietyCode === this.selectVariety.varietyCode) {
            this.$message.error(`该出库单出库商品中已有商品编号为:${item.varietyCode}的商品`)
            varietyCodeFlag = true
            return
          }
        }
        if (!varietyCodeFlag) {
          this.varietyDataSource.push(this.selectVariety)
        }
      }
      this.varietyVisible = !this.varietyVisible*/
      this.selectVariety.map(item => {
        item.number = ''
        item.totalprice = ''
      })
      for (let item of this.selectVariety) {
        this.varietyDataSource.push(item)
      }
      this.varietyVisible = !this.varietyVisible
    },
    varietyDelete(id) {// 第一个弹窗中删除商品
      const dataSource = [...this.varietyDataSource]
      this.varietyDataSource = dataSource.filter(item => item.varietyCode !== id)
    },
    saveOutOrderAddOrEdit() {// 保存新增或编辑出库单
      let allNumberFlag = true//是否所有的商品都有数量的标识

      // if (this.outOrder.carDerver === '') {
      //   this.$message.error('请输入司机')
      // } else if (this.outOrder.carNo === '') {
      //   this.$message.error('请输入车牌')
      // } else
      if (this.outOrder.stockOutUser === '') {
        this.$message.error('请输入出库人')
      } else if (this.outOrder.stockInTime === '') {
        this.$message.error('请选择出库时间')
      } else if (this.outOrder.user === '') {
        this.$message.error('请输入客户名称')
      } else if (this.outOrder.phone === '') {
        this.$message.error('请输入客户电话')
      } else if (this.outOrder.address === '') {
        this.$message.error('请输入客户地址')
      } else if (this.outOrder.logistics === '') {
        this.$message.error('请输入物流信息')
      } else if (this.outOrder.storehouse === '') {
        this.$message.error('请选择冷库')
      } else if (this.outOrder.businessPerson === '') {
        this.$message.error('请输入业务员')
      } else {
        for (let item of this.varietyDataSource) {
          if (item.number === '' || item.number === null) {
            this.$message.error('请输入数量')
            allNumberFlag = false
            return
          }
          if (!ifInteger(item.number)) {
            this.$message.error('商品数量必须为正整数')
            return
          }
        }
        if (allNumberFlag) {
          // 去掉varietyDataSource中每个对象（如果有）的uuid，此uuid是在前端生成的
          this.varietyDataSource.map(item => {
            delete item.uuid
          })
          this.outOrder.flowerOutorderinfoList = this.varietyDataSource// 将商品列表封装近outOrder中
          if (!this.outOrder.source) {
            this.outOrder.source = '手动出库'
          }
          if (this.addOrEditFlag === 'add') {// 新增出库单的情况
            flowerOutOrderAdd(this.outOrder).then(res => {
              if (res.success) {
                this.queryFlowerOutorder()
                this.$message.success('保存出库成功')
              } else {
                this.$message.error(res.message)
              }
              this.addOrEditVisible = !this.addOrEditVisible
            })
          } else {
            flowerOutOrderEdit(this.outOrder).then(res => {// 编辑出库单的情况
              if (res.success) {
                //this.queryFlowerOutorder()
                this.queryFlowerOutorderinfo(this.outOrderRecord.id)
                this.$message.success('保存成功')
              } else {
                this.$message.error(res.message)
              }
            })
          }
        }
        this.selectedRowKeys.length = 0//使新增或编辑后不显示批量删除的按钮
      }
    },
    cancelOutOrderAddOrEdit() {
      this.addOrEditVisible = false
    },
    outOrderDelete(id) {
      flowerOutOrderDelete({ id: id }).then(res => {
        if (res.success) {
          this.queryFlowerOutorder()
          this.$message.success('删除成功')
          this.addOrEditVisible = false
        } else {
          this.$message.error(res.message)
        }
      })
    },
    outOrderBatchDelete(selectedRowKeys) {
      if (selectedRowKeys.length > 0) {
        let ids = ''
        for (let item of selectedRowKeys) {
          ids = ids + item + ','
        }
        flowerOutOrderDeleteBatch({ ids: ids }).then(res => {
          if (res.success) {
            this.queryFlowerOutorder()
            this.selectedRowKeys.length = 0
            this.$message.success('批量删除成功')
          } else {
            this.$message.error(res.message)
          }
        })
      }
    },
    sureOut() {// 确认出库
      if (this.varietyDataSource.length === 0) {
        this.$message.error('至少需要有一个出库商品')
      } else {
        let allNumberFlag = true//是否所有的商品都有数量的标识
        for (let item of this.varietyDataSource) {
          if (item.number === '' || item.number === null) {
            this.$message.error('请输入数量')
            allNumberFlag = false
            return
          }
          if (!ifInteger(item.number)) {
            this.$message.error('商品数量必须为正整数')
            return
          }
        }
        if (allNumberFlag) {
          if (this.outorderInfoFlag) {// 如果已经有出库商品则直接确认出库
            flowerOutOrderSureOut({ id: this.outOrderRecord.id }).then(res => {
              if (res.success) {

                this.queryFlowerOutorder()
                this.$message.success('确认出库成功')
              } else {
                this.$message.error(res.message)
              }
              this.addOrEditVisible = false
            })
          } else {// 否则先保存数据然后再确认出库
            // console.log('this.outOrder=', this.outOrder)
            // if (this.outOrder.carDerver === '') {
            //   this.$message.error('请输入司机')
            // } else if (this.outOrder.carNo === '') {
            //   this.$message.error('请输入车牌')
            // } else
            //
            if (this.outOrder.stockOutUser === '') {
              this.$message.error('请输入出库人')
            } else if (this.outOrder.stockInTime === '') {
              this.$message.error('请选择出库时间')
            } else if (this.outOrder.user === '') {
              this.$message.error('请输入客户名称')
            } else if (this.outOrder.phone === '') {
              this.$message.error('请输入客户电话')
            } else if (this.outOrder.address === '') {
              this.$message.error('请输入客户地址')
            } else if (this.outOrder.storehouse === '') {
              this.$message.error('请选择冷库')
            } else if (this.outOrder.logistics === '') {
              this.$message.error('请输入物流信息')
            } else if (this.outOrder.businessPerson === '') {
              this.$message.error('请输入业务员')
            } else {
              // 将varietyDataSource中每个对象里面的id字段删除,此id字段是为了table中的key而在前端生成的
              for (let item of this.varietyDataSource) {
                delete item.id
              }
              if (!this.outOrder.source) {
                this.outOrder.source = '手动出库'
              }
              this.outOrder.flowerOutorderinfoList = this.varietyDataSource// 将商品列表封装近outOrder中
              flowerOutOrderEdit(this.outOrder).then(res => {// 编辑出库单的情况
                if (res.success) {
                  // 确认出库
                  flowerOutOrderSureOut({ id: this.outOrderRecord.id }).then(res => {
                    if (res.success) {
                      this.queryFlowerOutorder()
                      this.$message.success('确认出库成功')
                    } else {
                      this.$message.error(res.message)
                    }
                  })
                } else {
                  this.$message.error(res.message)
                }
                this.addOrEditVisible = false
              })
            }
          }
        }
      }

    },
    toWaitOut() {// 撤销出库
      flowerOutOrderToWaitOut({ id: this.outOrderRecord.id }).then(res => {
        if (res.success) {
          this.queryFlowerOutorder()
          this.$message.success('撤销出库成功')
        } else {
          this.$message.error(res.message)
        }
        this.addOrEditVisible = false
      })
    },
    numberChange(record, number, totalPrice) {
      let result = 0
      if (ifInteger(number) && (number !== null || number !== '') && (totalPrice !== null || totalPrice !== '')) {
        if (number == 0 || number == '0') {
          record.number = null
          record.price = null
        } else {
          let price = (totalPrice * 10 / 10) / (number * 10 / 10)
          record.price = parseFloat(price).toFixed(2)
        }
      }

      if ((totalPrice !== null || totalPrice !== '')) {// 计算出总价合计
        this.allTotalPrice = 0
        this.allTotalNum = 0
        for (let item of this.varietyDataSource) {
          this.allTotalPrice += (item.totalprice * 10 / 10)
          this.allTotalNum += parseInt(item.number)
        }
      }
    },
    //拆分订单
    toMuniyOrders(record) {
      this.toMuiDialogVisible = true
      this.initFlowerStorehouse(record)
      this.hoseLoading = true
      this.orderDetailID = record.id
      this.orderDetailTotalNumber = record.number
      if (this.orderDetailTotalNumber == 0) {
        this.$message.error('出库数量为0，请重新填写后才能拆分')
        return
      }
      //查询数据 list
      flowerOutOrderDList({ 'mainid': record.id }).then((res) => {
        if (res.success) {
          this.selectedHoseDataSource = res.result.records
        } else {
          this.$message.error(res.message)
        }
        this.hoseLoading = false
      })

    },


    afterSaleModalShow(record) {// 打开售后订单的modal
      this.afterSale = {
        orderNo: '',//销售单号
        afOrderNo: '',//售后单号
        totalPrice: '',//货损金额
        responsibility: '',//责任判定
        reason: ''//售后理由
      }
      this.afterSaleSource = []
      this.queryFlowerAfSalesMain(record.sealNo)
      this.afterSaleVisible = !this.afterSaleVisible
    },
    queryFlowerAfSalesMain(sealNo) {// 查询售后单，sealNo为销售单号
      let params = {
        orderNo: sealNo
      }
      flowerAfSalesMain(params).then(res => {
        // console.log('===', res)
        if (res.success) {
          this.afterSale = res.result
          this.afterSaleSource = res.result.flowerAfSalesDetalList
        } else {
          this.$message.error(res.message)
        }
      })
    },
    suerAfterSale() {//售后单弹窗的确定按钮
      this.afterSaleVisible = false
    },

    handleExportXlsAccont(record) {
      let fileName = '结算单' + record.orderNo
      let param = this.getQueryParams()
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(',')
      }
      // console.log('导出参数', param)
      let urlss = '/flower/flowerOutorder/exportXlsForAccont'
      downFile(urlss, record).then((data) => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xlsx')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xlsx')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
        }
      })
    }
    ,
    initFlowerStorehouse(record) {
      // getFlowerStorehouse({ 'cost': record.cost }).then((res) => {
      //   if (res.success) {
      //     this.hoseList = res.result.records
      //   } else {
      //     this.$message.error(res.message)
      //   }
      // })
    },
    finalSure() {
      this.sureOutLoading =true
      let id = this.outOrderRecord.id
      fiunalSure({ id: id }).then(res => {
        if (res.success) {
          this.queryFlowerOutorder()
          this.$message.success('扣款成功！')
        } else {
          this.$message.error(res.message)
        }
        this.addOrEditVisible = !this.addOrEditVisible
        this.sureOutLoading =false
      }).finally(() => {

      })

    },
    finalSureBack() {
      this.sureOutLoading =true
      let id = this.outOrderRecord.id
      fiunalSureBack({ id: id }).then(res => {
        if (res.success) {
          this.queryFlowerOutorder()
          this.$message.success('撤销扣款成功！')
        } else {
          this.$message.error(res.message)
        }
        this.addOrEditVisible = !this.addOrEditVisible
        this.sureOutLoading =false
      }).finally(() => {

      })
    },

    handleExportXlsAll() {
      let fileName = '出库单(全部)'
      let param = this.queryParams
      this.exportLoading =true

      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(',')
      }
      let urlss = '/flower/flowerOutorder/exportXlsAll'
      downFile(urlss, param).then((data) => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xlsx')
          this.exportLoading = false
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xlsx')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
        }
      })
    },
    handleExportXlsList() {
      this.exportLoading =true
      let dt = new Date()
      let fileName = '出库单' + dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate()
      let param = this.queryParams
      // param.state = 0
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(',')
      }
      // console.log('导出参数', param)
      let urlss = '/flower/flowerOutorder/exportXlsAll'
      downFile(urlss, param).then((data) => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xlsx')
          this.exportLoading = false
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xlsx')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
          this.exportLoading = false
        }
      })
    },
    queryCustomMoney(userId){//查询客户余额
      getCustomMoney({'userId':userId}).then(res=>{
        if (res.success){
          this.outOrder.customMoney=res.result
        }else {
          this.$message.error('获取客户余额失败')
        }
      })
    },
    //账期单选的change
    periodChange(e) {
      this.outOrder.period = e.target.value
    },
    getPeriod() {
      period().then(res => {
        this.periodList = res
      })
    }, //是否开票的单项
    isinvoiceChange(e) {
      this.outOrder.isinvoice = e.target.value
    },
    handleExportXlsOut(record) {
      const token = Vue.ls.get(ACCESS_TOKEN);
      let url = window._CONFIG['jimuURL'] + "/jmreport/shareView/748391289810227200?id="+record.id+"&token="+token
      // let url =  "http://scht.ythxdny.com:9998/jmreport/shareView/748391289810227200?id="+record.id+"&token="+token
      window.open(url)
    },
    // handleExportXlsOut(record) {
    //   let fileName = '出库单' + record.orderNo
    //   let param = this.getQueryParams()
    //   if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
    //     param['selections'] = this.selectedRowKeys.join(',')
    //   }
    //   let urlss = '/flower/flowerOutorder/exportXlsForOut'
    //   downFile(urlss, record).then((data) => {
    //     if (!data) {
    //       this.$message.warning('文件下载失败')
    //       return
    //     }
    //     if (typeof window.navigator.msSaveBlob !== 'undefined') {
    //       window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xlsx')
    //     } else {
    //       let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
    //       let link = document.createElement('a')
    //       link.style.display = 'none'
    //       link.href = url
    //       link.setAttribute('download', fileName + '.xlsx')
    //       document.body.appendChild(link)
    //       link.click()
    //       document.body.removeChild(link) //下载完成移除元素
    //       window.URL.revokeObjectURL(url) //释放掉blob对象
    //     }
    //   })
    // },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';

.editable-cell {
  position: relative;
  background-color: #0c8fcf;
}
.ant-col-6, .ant-col-7, .ant-col-8, .ant-col-12 {
  /*margin-top: 3px;*/
  height: 40px;
}

</style>